<?php

namespace App\Shop\Controllers;

use App\Http\Controllers\Controller;
use App\Models\GoodOrder;
use App\Models\ServiceOrder;
use Dcat\Admin\Admin;
use Dcat\Admin\Layout\Column;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Layout\Row;
use Dcat\Admin\Widgets\Card;
use Illuminate\Support\Facades\Auth;

class HomeController extends Controller
{
    public function index(Content $content)
    {
        return $content
            ->header('控制台')
            ->body(function (Row $row) {
                $admin = Admin::user();
                $isShop = $admin->isAdministrator();
                if ($isShop){
                    $shop_id = $admin->id;
                }else{
                    $shop_id = $admin->shop_id;
                }
                $row->column(12, function (Column $column) use ($admin) {
                    $weeks = ['星期日','星期一','星期二','星期三','星期四','星期五','星期六'];
                    $props = [
                        'user'=>['name'=>"账号",'username'=>$admin['username']],
                        'date'=>date("Y年m月d日")." ".$weeks[date("w")],
                        'times'=>date("H:i:s"),'weeks'=>$weeks
                    ];
                    $card = Card::make("欢迎店铺管理员",view('shop.home.index',$props));
                    $column->row($card);

                });
                $data['order'] = [
                    'good_num'=>GoodOrder::query()->where("shop_id",$shop_id)->where("state",1)->count(),
                    'wait_num'=>ServiceOrder::query()->where("is_apply",0)->where("shop_id",$shop_id)->where("worker_id",0)->where("status",0)->count(),
                    'order_num'=>ServiceOrder::query()->where("is_apply",0)->where("shop_id",$shop_id)->where("worker_id",">",0)->where("status",0)->count(),
                ];
                $data['num'] = array_sum($data['order']);
                $row->column(12,view('shop.basic.wait',$data));
            });
    }

}
